package registnet.cpm.util;

import registnet.cpm.Project;
import registnet.cpm.Node;

/**
 * A visitor implementation which computes the early start
 * and the early finish of a node.
 */
public class EarlyStartEarlyFinishImp implements IVisitor {

	@Override
	public void visit(Project project, Node node) {
		if(!project.hasPredecessor(node)){
			node.setEarlyStart(0);
			node.setEarlyFinish(node.getValue());
		}else{
			node.setEarlyStart(0);
			for(int i=0; i<project.getPredecessors(node).size(); i++)
				if(node.getEarlyStart() < project.getPredecessors(node).get(i).getEarlyFinish())
					node.setEarlyStart(project.getPredecessors(node).get(i).getEarlyFinish());
			node.setEarlyFinish(node.getEarlyStart()+node.getValue());
		}
	}

}
